<?php
    include_once("checkAuthenticationAction.php");
    include_once("../service/categoryService.php");
    
    $option_id = (isset($_POST["edit_option_id"])?$_POST["edit_option_id"]:0);
    $title = $_POST["optionTitle"];
	$options = isset($_POST["selectedOptionItems"])?$_POST["selectedOptionItems"]:array();
    
    updateOption($option_id,$title);
	for($i = 0; $i < count($options); $i++){
        if(!is_numeric($options[$i])){
            createOptionItem($option_id,$options[$i]);             
        }
    }
	echo "<script>window.location.href='../admin/optionitemdetail.php?action=9&id=".$option_id."';</script>";
?>
